#include "StdAfx.h"
#include "WorldSession.h"
#include "../GameDefine/Util.h"
#include "WorldServer.h"
#include "WorldClient.h"
#include "DBSocket.h"

DBSocket* WorldSession::m_pSend2DB = NULL;

CodesHandler<WorldSession> worldsessiontable[NS_Type_Nums] =
{
	//{"NS_PlayerAuthSession", NS_PlayerAuthSession, &WorldSession::SendMsg}
};

void WorldSession::ExecuteOpcode(tagMessage* m)
{
	if(m->dwHDCode<NS_Type_Nums)
		(this->*(worldsessiontable[m->dwHDCode].handler))(m);
	else
	{
		assert(0);
		sLog.Write("code is over");
	}
}

WorldSession::WorldSession(char* PlayerName, WorldClient* p)
{
	strncpy(m_szPlayerName, PlayerName, 32);
	m_dwPlayerID = Util::BKDRHash(m_szPlayerName);
	m_pClient = p;

	m_pSend2DB = & DBSocket::Inst();
}

WorldSession::~WorldSession(void)
{
}

void WorldSession::Stop()
{

}

void WorldSession::Update()
{
	m_pClient->HandleMessage();
}

DWORD WorldSession::GetPlayerID()
{
	return m_dwPlayerID;
}

bool WorldSession::GetPlayerState(EPLAYERSTATE s)
{
	return m_eState==s;
}

bool WorldSession::SetPlayerState(EPLAYERSTATE s)
{
	m_eState = s;
	return true;
}

void WorldSession::SendMsg(tagMessage* lp, DWORD dwSize)
{
	return m_pClient->AddSendMsg(lp,dwSize);
}
